package com.meessiom.train.crm.refund.controller;

import com.meessiom.train.crm.refund.model.Refund;
import com.meessiom.train.crm.refund.service.RefundService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/api/v1/refunds")
@Slf4j

public class RefundController {
    @Autowired
    private RefundService refundService;

    @GetMapping
    public List<Refund> getAllRefunds(){
        return refundService.getAllRefunds();
    }

    @PostMapping
    public Refund createRefund(@RequestBody Refund refund){
        return refundService.createRefund(refund);
    }

    @DeleteMapping("{id}")
    public ResponseEntity<HttpStatus> deleteRefund(@PathVariable long id){
        refundService.deleteRefund(id);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @PutMapping({"{id}"})
    public ResponseEntity<Refund> updateRefund(@PathVariable long id, @RequestBody Refund refundDetails){
        Refund updateRefund = this.refundService.updateRefund(id, refundDetails);
        return ResponseEntity.ok(updateRefund);
    }

    @GetMapping("{id}")
    public ResponseEntity<Refund> getRefundById(@PathVariable long id) {
        Refund refund = this.refundService.getRefundById(id);
        return ResponseEntity.ok(refund);
    }
}
